<?php
// 党务村务公开
namespace app\home\controller;
use think\Db;
class Jcopen extends HomeBase {
	// 左侧列表数据
	public function getlist(){

		$order = input('order');
		if($order){
			$order='id DESC';
		}// 排序
		//通过mark值进行选择三务数据 默认村务
			$cunwu=Db::name('Cat')->where(['mark'=>'cunwu'])->field('id,title,mark')->order($order)->select();
			$dangwu=Db::name('Cat')->where(['mark'=>'dangwu'])->field('id,title,mark')->order($order)->select();
			$shiwu=Db::name('Cat')->where(['mark'=>'shiwu'])->field('id,title,mark')->order($order)->select();
			//合并数组
		$info=array_merge($cunwu,$dangwu,$shiwu);
		if($info){
			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0;
			$datas['info']='无数据！';
		}
		return json($datas);

	}
	//首页三务框的信息展示
	public function getwulist() {
		$cunwuid = array();
		$mark2 = input('mark2');		// 分类
		$order = input('order');
		if(!$order){
			$order='id DESC';
		}
			//村务
			$cunwuids = Db::name('Cat')->where('mark',$mark2)->field('id')->select();
			foreach($cunwuids as $k => $v){
				$cunwuid[$k]=$v['id'];
			}
			$list1 = Db::name('Jcopen')->where('catid','in',$cunwuid)->order($order)->field('id,title,catid,bsid')->select();

		if (!empty($list1)){
			$datas['status']=1;
			$datas['info']=$list1;
			return json($datas);

		}else {
			return json(array('status'=>0,'msg'=>'暂无数据'));
		}

	}
	public function getDangwu(){
	   $dangwuid = array();
	   $mark1 = input('mark1');		// 分类
	   if(!$mark1){
		$datas['status']=0;
		$datas['info']="无数据";
	   }else{
		//党务
		$dangwuids = Db::name('Cat')->where('mark',$mark1)->field('id')->select();
		foreach($dangwuids as $k => $v){
		   $dangwuid[$k]=$v['id'];
		}
		$list2 = Db::name('Jcopen')->where('catid','in',$dangwuid)->field('id,title,catid,bsid')->select();
		if($list2){
		  $datas['status']=1;
		  $datas['info']=$list2;

		}else{
		 $datas['status']=0;
		$datas['info']="无数据"; 
		}
	   }
		return json($datas);
	}
	//右侧列表数据 第一层详情
	public function getdetail() {
		$current=input('current');
		if(!$current){
			$current=1;
		}
		$pagenums=input('pagenums');
		if(!$pagenums){
			$pagenums=50;
		}
		$nowpagenums=($current-1)*$pagenums;
		$order=input('order');
		if(!$order){
			$order='id DESC';
		}

		$total=Db::name('Jcopen')->count('id');
		$id = input('bsid');
		$id = intval($id);
		if($id){
			$info = Db::name('Jcopen')
					->where('catid',$id)
					->order($order)
					->limit($nowpagenums,$pagenums)
					->select();
				if ($info){
					$datas['status']=1;
					$datas['info']=$info;
					$datas['total']=$total;
					$datas['current']=$current;
				}else{
					$datas['status']=0;
					$datas['info']='无数据';
					$datas['total']=$total;
					$datas['current']=$current;
				}
		}else{
			$datas['status']=0;
			$datas['info']='参数确失!';
		}
		return json($datas);
	}
	/*
 * 获取右侧列表数据点击后的详细信息
 * pid
 */
	function getmessage(){
		$id = input('id');
		$id = intval($id);
		if($id){
			$info = Db::name('Jcopen')->where('id',$id)->find();
			if ($info){
				return json(array('status'=>1,'info'=>$info));
			}else{
				return json(array('status'=>0,'info'=>'无数据'));
			}
		}else{
			return json(array('status'=>0,'info'=>'无参数'));
		}

	}
}